package com.it2297.view;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTextField;

import com.it2297.controller.CustomerController;
import com.it2297.main.UserApp;
import com.it2297.model.User;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;

public class UpdateCustomerView extends JPanel {
	private final CustomerController ucc = new CustomerController(this);
	
	private final JLabel lblUpdatePersonalParticulars = new JLabel("Update Personal Particular");
	private final JLabel lblName = new JLabel("Name");
	private final JLabel lblEmail = new JLabel("Email");
	private final JLabel lblContactNumber = new JLabel("Contact Number ");
	private final JLabel lblAddress = new JLabel("Address");
	private final JButton btnUpdate = new JButton("Update ");
	private final JTextField name_TF = new JTextField();
	private final JTextField email_TF = new JTextField();
	private final JTextField phone_TF = new JTextField();
	private final JTextField address_TF = new JTextField();
	private final JLabel lblPassword = new JLabel("Password");
	private final JLabel lblIdentificationNumber = new JLabel("Identification Number ");
	private final JTextField nric_TF = new JTextField();
	private final JPasswordField password_TF = new JPasswordField();

	/**
	 * Create the panel./
	 */
	public UpdateCustomerView() {
		nric_TF.setEditable(false);
		nric_TF.setBounds(172, 70, 151, 22);
		nric_TF.setColumns(10);
		nric_TF.setText(UserApp.getCurrentUser().getNric());
		address_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		address_TF.setBounds(172, 323, 191, 64);
		address_TF.setColumns(10);
		address_TF.setText(UserApp.getCurrentUser().getAddress());
		phone_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		phone_TF.setBounds(172, 251, 151, 23);
		phone_TF.setColumns(10);
		phone_TF.setText(UserApp.getCurrentUser().getPhone());
		email_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		email_TF.setBounds(172, 189, 219, 22);
		email_TF.setColumns(10);
		email_TF.setText(UserApp.getCurrentUser().getEmail());
		name_TF.setBounds(172, 125, 178, 21);
		name_TF.setColumns(10);
		name_TF.setText(UserApp.getCurrentUser().getName());

		initGUI();
	}
	private void initGUI() {
		setLayout(null);
		lblUpdatePersonalParticulars.setFont(new Font("Arial", Font.BOLD, 15));
		lblUpdatePersonalParticulars.setBounds(21, 11, 281, 48);
		
		
		add(lblUpdatePersonalParticulars);
		lblName.setFont(new Font("Arial", Font.PLAIN, 12));
		lblName.setBounds(42, 123, 46, 23);
		
		add(lblName);
		lblEmail.setFont(new Font("Arial", Font.PLAIN, 12));
		lblEmail.setBounds(42, 188, 46, 23);
		
		add(lblEmail);
		lblContactNumber.setFont(new Font("Arial", Font.PLAIN, 12));
		lblContactNumber.setBounds(42, 251, 102, 23);
		
		add(lblContactNumber);
		lblAddress.setFont(new Font("Arial", Font.PLAIN, 12));
		lblAddress.setBounds(42, 323, 67, 23);
		add(lblAddress);
		
		btnUpdate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ucc.update();
			
			}
		});
		btnUpdate.setFont(new Font("Arial", Font.PLAIN, 12));
		btnUpdate.setBounds(180, 520, 89, 23);
		
		add(btnUpdate);
		
		add(name_TF);
		
		add(email_TF);
		
		add(phone_TF);
		
		add(address_TF);
		lblPassword.setFont(new Font("Arial", Font.PLAIN, 12));
		lblPassword.setBounds(42, 431, 89, 23);
		
		add(lblPassword);
		lblIdentificationNumber.setFont(new Font("Arial", Font.PLAIN, 12));
		lblIdentificationNumber.setBounds(42, 70, 132, 23);
		
		add(lblIdentificationNumber);
		
		add(nric_TF);
		password_TF.setFont(new Font("Arial", Font.PLAIN, 12));
		password_TF.setBounds(172, 433, 115, 20);
		password_TF.setText(UserApp.getCurrentUser().getPassword());

		add(password_TF);
	}
	public String getName() {
		return name_TF.getText();
	}
	
	public String getAddress() {
		return address_TF.getText();
	}
	
	public String getEmail() {
		return email_TF.getText();
	}
	
	public String getPhone() {
		return phone_TF.getText();
	}
	
	public String getNric() {
		return nric_TF.getText();
	}
	
	public String getPassword(){
		String password = "";
		for(int i=0; i<password_TF.getPassword().length;i++){
			password += password_TF.getPassword()[i];
		}
		return password;
	}
	public void setEmail(String email) {
		email_TF.setText(email);
	}
	public void setAddress(String address) {
		address_TF.setText(address);
	}
	public void setPhone(String phone) {	
		phone_TF.setText(phone);

	}
	public void setPassword(String password) {
		password_TF.setText(password);
	
	}
	public void setNric(String nric) {	
		nric_TF.setText(nric);

	}
	public void setName(String name) {	
		name_TF.setText(name);

	}
	
}
